<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*, java.text.*;" errorPage=""%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <%! DateFormat tipe = new SimpleDateFormat("EEE, MMM d, yyyy");
    Calendar cal = Calendar.getInstance();%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="includes/estilo.css" rel="stylesheet" type="text/css">
<title>Lista de itens da Nota Fiscal</title>
</head>
<body onLoad="this.focus();">
<table border="0" align="center" cellpadding="0" cellspacing="0" width="770px">
	<tr>
	<td height="100px">
		<table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
		<tr>
			<td align="center" width="100px"> <font color="#191970" size="1"><%=(tipe.format(cal.getTime()))%></font></td>
			<td width="30px"></td>
			<td><center><font color="blue" size="4"><b>Itens da nota: <%=request.getParameter("fiscalNo")%></b></font></center></td>
			<td align="right" width="100px"><img src="imagens/logoDican.jpg" width="100px"></td>
		</tr>
		<tr>
			<td colspan=4 align="right"><input name="Button" type="button" class="botaoazul" style="width:80px" value="Imprimir" onclick="javascript:window.open('ImprimePedido?pedId=<%=request.getParameter("faturaId") %>&relatname=danfeR','_newtab');"></td>
		</tr>
		</table>
	</td>
	</tr>
	<tr>
		<td><font size="1">Os itens e a nota est&atilde;o sujeitos a altera&ccedil;&atilde;o</font></td>
	</tr>
	<tr>
		<td><hr color=navy size=3></td>
	</tr>
	<tr>
	<td>
		<table align="center" cellpadding="0" cellspacing="0" width="100%" style="border-bottom: solid 2px black;margin-bottom: 20px">
			<tr bgcolor="#696969" height="25px">
				<td align="center" width="120px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>NOTA</b></font></td>
				<td align="center" width="90px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>ORIGEM</b></font></td>
				<td align="left" width="440px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>CLIENTE</b></font></td>
				<td align="center" width="120px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>EMISS&Atilde;O</b></font></td>
			</tr>
			<sql:query dataSource="jdbc/postgres" var="dadosCabecalho">
				SELECT AD.name as origem, B.name as cliente,I.dateinvoiced::date as emissao, i.totallines totalProdutos, i.grandtotal totalNota, i.em_nfe_chaveacesso chaveAcesso
				FROM C_INVOICE I
				INNER JOIN AD_ORG AD ON I.AD_ORG_ID = AD.AD_ORG_ID
				INNER JOIN C_BPARTNER B ON B.C_BPARTNER_ID=I.C_BPARTNER_ID 
				WHERE I.C_INVOICE_ID = ? ORDER BY I.dateinvoiced ASC LIMIT 1;
				<sql:param><%=request.getParameter("faturaId") %></sql:param>
			</sql:query>
			<c:forEach var="dadoCabecalho" items="${dadosCabecalho.rows}">
				<tr bgcolor="#FFFFFF" height="30px">
					<td align="center" style="border-top: solid 1px black; border-left: solid 2px black;"><font size="1"><%=request.getParameter("fiscalNo") %></font></td>
					<td align="center" style="border-top: solid 1px black; "><font size="1">${dadoCabecalho.origem }</font></td>
					<td style="border-top: solid 1px black;"><font size="1">${dadoCabecalho.cliente}</font></td>
					<td align="center" style="border-top: solid 1px black;border-right: solid 2px black;"><font size="1">&nbsp;${dadoCabecalho.emissao}</font></td>
				</tr>
			</c:forEach>
		</table>
	</td>
	</tr>
	<tr>
	<td>
	<table align="center" cellpadding="0" cellspacing="0" width="100%" style="border-bottom: solid 2px black;margin-bottom: 10px">
	<tr bgcolor="#696969" height="25px">
		<td align="center" width="120px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>CODIGO</b></font></td>
		<td align="left" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>DESCRI&Ccedil;&Atilde;0</b></font></td>
		<td align="center" width="120px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>QUANTIDADE</b></font></td>
	</tr>
	<sql:query dataSource="jdbc/postgres" var="itensNota">
		SELECT M.VALUE codProd,M.NAME nomeProd,IL.QTYINVOICED qtdFat FROM C_INVOICELINE IL INNER JOIN M_PRODUCT M ON M.M_PRODUCT_ID=IL.M_PRODUCT_ID WHERE IL.C_INVOICE_ID=? ORDER BY M.VALUE DESC;
		<sql:param><%=request.getParameter("faturaId") %></sql:param>
	</sql:query>
	<c:forEach var="itemNota" items="${itensNota.rows}" varStatus="count">
		<tr class="${count.index % 2 == 0 ? 'even' : 'odd'}" height="30px">
			<td align="center" style="border-top: solid 1px black; border-left: solid 2px black;"><font size="1">${itemNota.codProd}</font></td>
			<td align="left" style="border-top: solid 1px black;"><font size="1">${itemNota.nomeProd}</font></td>
			<td align="right" style="border-top: solid 1px black;border-right: solid 2px black;"><font size="1">${itemNota.qtdFat}&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
		</tr>
	</c:forEach>
	</table>
</table>
<table border="0" align="center" cellpadding="0" cellspacing="0" width="770px">
<tr>
	<td colspan="3"><hr color=navy size=3></td>
</tr>
<tr>
	<c:forEach var="dadoRodape" items="${dadosCabecalho.rows}">
		<td align="left"><font size="1">Chave de acesso:</font><br/><font size="2"><b>${dadoRodape.chaveAcesso}</b></font></td>
		<td align="center"><font size="2">Valor dos Produtos:<br/><b><fmt:formatNumber value="${dadoRodape.totalProdutos}" type="currency"/></b></font></td>
		<td align="center"><font size="2">Valor Total da Nota:<br/><b><fmt:formatNumber value="${dadoRodape.totalNota}" type="currency"/></b></font></td>
	</c:forEach>
</tr>
<tr>
</table>
</body>
</html>